// packageF/stats/stats.js
import urilt from "../../utils/util";
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statsData:{},
    cardDay:'month', //判断我的收入是否本月还是本天的业绩
    orderDay:'month', //判断团队订单业绩是否本月还是本天的业绩
    orderList: [
      {
        nameClass: 'icon-fontclass-daifukuan',
        title: '待支付',
        navigation: '/packageF/teamOrder/teamOrder?status=0',
        status:0
      },
      {
          nameClass: 'icon-fontclass-daifahuo',
          title: '待发货',
          navigation: '/packageF/teamOrder/teamOrder?status=1',
          status:1
      },
      {
          nameClass: 'icon-fontclass-daishouhuo1',
          title: '待收货',
          navigation: '/packageF/teamOrder/teamOrder?status=2',
          status:2
      },
      {
          nameClass: 'icon-fontclass-shouhouliebiao',
          title: '售后列表',
          navigation: '/packageF/teamOrder/teamOrder?status=4',
          status:4
          // code:'completed_num',
          // num:0
      },
      {
          nameClass: 'icon-fontclass-quanbudingdan',
          title: '全部订单',
          navigation: '/packageF/teamOrder/teamOrder?status=-999',
          status:-999
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.statsData();
  },
  statsData() {
    let urlStr = app.getNetAddresss("plugin.team-analysis.frontend.index.index");
    console.log(urlStr + '>>>>>');
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          console.log(res + '????????');
          this.setData({
            statsData: res.data
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  onOrderTo(e) {
    console.log(e);
    let navTo = e.currentTarget.dataset.navto;
    let status = e.currentTarget.dataset.status;
    let startTime = '';
    let endTime = '';
    if(status === -999) { //如果是全部订单传的时间段设置为0和10个9
      startTime = 0;
      endTime = 9999999999;
    } else {
      if(this.data.orderDay === 'month') { //区别调整查询的是当月的业绩/收益还是当日
        startTime = this.data.statsData.month_timestamp?.start_time;
        endTime = this.data.statsData.month_timestamp?.end_time;
      } else {
        startTime = this.data.statsData.day_timestamp?.start_time;
        endTime = this.data.statsData.day_timestamp?.end_time;
      }
    }
    wx.navigateTo({
      url: `${navTo}&start_time=${startTime}&end_time=${endTime}`,
    })
  },
  onMyevent(paramData) {
    console.log(paramData);
    console.log('测试传的值');
    let cardDay = paramData.detail.timeCard;
    let typename = paramData.detail.typename;
    console.log(typename);
    if(typename === "income") { //区别是查看总收益的今天还是团队订单总业绩的今天
      this.setData({
        cardDay:cardDay
      });
    } else {
      this.setData({
        orderDay:cardDay
      });
    }
    
  },
  onSeconds(paramData) {
    let typeName = paramData.detail;
    let startTime = '';
    let endTime = '';
    if(typeName == 'income') {
      if(this.data.cardDay === 'month') { //区别调整查询的是当月的业绩/收益还是当日
        startTime = this.data.statsData.month_timestamp?.start_time;
        endTime = this.data.statsData.month_timestamp?.end_time;
      } else {
        startTime = this.data.statsData.day_timestamp?.start_time;
        endTime = this.data.statsData.day_timestamp?.end_time;
      }
      wx.navigateTo({
        url: `/packageF/balance/balance?status=0&start_time=${startTime}&end_time=${endTime}`,
      })
    } else {
      startTime = 0;
      endTime = 9999999999;
      wx.navigateTo({
        url: `/packageF/teamOrder/teamOrder?status=-999&start_time=${startTime}&end_time=${endTime}`,
      })
    }
  },
  onWithdrawal() {
    wx.navigateTo({
      url: '/packageA/member/withdrawal/withdrawal',
    })
  },
  secondLevel() { //跳转收入二级页面
    wx.navigateTo({
      url: '/packageF/incomeDetail/incomeDetail',
    })
  },
  onOrder() {
    wx.navigateTo({
      url: '/packageF/performance/performance',
    })
  },
  onClient(event) { //跳转到三级页面
    let id = event.currentTarget.dataset.id;
    if(id === 0) {
      wx.navigateTo({
        url: '/packageF/clientDetails/clientDetails',
      })
    } else {
      wx.navigateTo({
        url: `/packageF/gradeDetails/gradeDetails?diviLevel=${id}`,
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})